#include "cmsis_os2.h"
#include "lvgl.h"


extern osMutexId_t LvglMutexHandle;


void StartLvglTask(void *argument)
{
    osMutexAcquire(LvglMutexHandle, osWaitForever);

    lv_obj_t* tileview = lv_tileview_create(lv_scr_act());                              /* 创建平铺视图部件 */
    lv_obj_t* tile_1 = lv_tileview_add_tile(tileview, 0, 0, LV_DIR_RIGHT );             /* 添加页面 1 - 可右滑 */
    lv_obj_t* tile_2 = lv_tileview_add_tile(tileview, 1, 0, LV_DIR_LEFT|LV_DIR_RIGHT ); /* 添加页面 2 - 可左/右滑 */
    lv_obj_t* tile_3 = lv_tileview_add_tile(tileview, 2, 0, LV_DIR_LEFT);               /* 添加页面 3 - 可左滑 */
    
    lv_obj_t* label_1 = lv_label_create(tile_1);                                        /* 创建标签 */
    lv_label_set_text(label_1, "Page_1");                                               /* 设置文本内容 */
    lv_obj_set_style_text_font(label_1, &lv_font_montserrat_24, LV_STATE_DEFAULT);      /* 设置字体 */
    lv_obj_center(label_1);                                                             /* 设置位置 */

    lv_obj_t* label_2 = lv_label_create(tile_2);                                        /* 创建标签 */
    lv_label_set_text(label_2, "Page_2");                                               /* 设置文本内容 */
    lv_obj_set_style_text_font(label_2, &lv_font_montserrat_24, LV_STATE_DEFAULT);      /* 设置字体 */
    lv_obj_center(label_2);                                                             /* 设置位置 */

    lv_obj_t* label_3 = lv_label_create(tile_3);                                        /* 创建标签 */
    lv_label_set_text(label_3, "Page_3");                                               /* 设置文本内容 */
    lv_obj_set_style_text_font(label_3, &lv_font_montserrat_24, LV_STATE_DEFAULT);      /* 设置字体 */
    lv_obj_center(label_3);                                                             /* 设置位置 */

    lv_obj_remove_style(tileview, NULL, LV_PART_SCROLLBAR);                             /* 移除滚动条 */

    osMutexRelease(LvglMutexHandle);

    for(;;)
    {
        osMutexAcquire(LvglMutexHandle, osWaitForever);
        lv_timer_handler();
        osMutexRelease(LvglMutexHandle);
        osDelay(5);
    }
}
